<template>
  <div>
    <!--最外层容器-->
    <el-container>
      <!--侧边栏-->
      <el-aside :width="asideWidth" style=" min-height: 100vh; background-color: #001529">
        <!--logo区域-->
        <div id="logo" @click="$router.push('/')">
          <img src="@/assets/logo.png" alt="" style="width: 40px; height: 40px;">
          <span class="logo-title" v-show="!isCollapse">智能图片助手</span>
        </div>
        <!--菜单栏-->
        <el-menu router :collapse="isCollapse" :collapse-transition="false" background-color="#001529"
                 text-color="rgba(255,255,255,0.65)" active-text-color="#fff" style="border: none"
                 :default-active="$route.path">
          <el-menu-item index="/ai">
            <i class="el-icon-chahuatubiao"></i>
            <span slot="title">作图</span>
          </el-menu-item>
          <el-menu-item index="/peopleToAnime">
            <i class="el-icon-chuyin"></i>
            <span slot="title">人像动漫化</span>
          </el-menu-item>
          <el-menu-item index="/stylisticShifts">
            <i class="el-icon-zhuanhuan"></i>
            <span slot="title">风格转换</span>
          </el-menu-item>
          <el-menu-item index="/imgRecognize">
            <i class="el-icon-renlianshibie"></i>
            <span slot="title">人脸识别</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-container>
        <!--头部横栏-->
        <el-header>
          <i :class="collapseIcon" style="font-size: 26px" @click="handleCollapse"></i>

          <el-breadcrumb separator="/" style="margin-left: 20px;">
            <el-breadcrumb-item :to="{ path: $route.path }">{{ $route.meta.name }}</el-breadcrumb-item>
          </el-breadcrumb>

          <div style="flex: 1; display: flex; width: 0; align-items: center; justify-content: flex-end">
            <i class="el-icon-full-screen" style="font-size: 26px; cursor: pointer" @click="handleFull"></i>
          </div>
        </el-header>
        <!--主体部分-->
        <el-main>
          <router-view @update:user="updateUser"/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>

export default {
  name: 'ManagerView',
  data() {
    return {
      isCollapse: false, //默认不收缩
      asideWidth: '200px', //侧边栏默认宽度
      collapseIcon: 'el-icon-s-fold',
      loginUser: JSON.parse(localStorage.getItem('user')) || {},
    }
  },
  //vue实例创建后，还没渲染数据时，自动执行的操作
  created() {
  },
  //页面完成渲染后自动执行的操作
  mounted() {
  },
  methods: {
    //接收子组件的用户更新消息
    updateUser() {
      // this.loginUser=loginUser//传递引用导致两个loginUser引用同一个对象，造成两者同时变化，这是不希望的
      // this.loginUser=JSON.parse(JSON.stringify(loginUser))//深克隆就能解决这个问题
      this.loginUser = JSON.parse(localStorage.getItem('user')) || {}  //相当于这个方法
    },
    handleCollapse() {
      this.isCollapse = !this.isCollapse;
      this.asideWidth = this.isCollapse ? '64px' : '200px';
      this.collapseIcon = this.isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
    },
    handleFull() {
      if (document.fullscreen) {
        document.exitFullscreen();
      } else {
        document.documentElement.requestFullscreen();
      }
    },
    logout() {
      localStorage.removeItem('user')
      this.$router.push('/login')
    }
  },
  components: {}
}
</script>

<style scoped>
#logo {
  height: 60px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#logo:hover {
  color: #1989fa;
}

.el-menu--inline .el-menu-item {
  background-color: #000c17 !important;
  padding-left: 45px !important;
}

.el-menu--inline {
  background-color: #000c17 !important;
}

.el-menu-item:hover, .el-menu-item:hover i, .el-submenu__title:hover, .el-submenu__title:hover i {
  color: #fff !important;
}

.el-menu-item.is-active {
  background-color: #1890ff !important;
  border-radius: 5px;
}

.el-menu.el-menu--inline .el-menu-item.is-active {
  padding-left: 45px !important;
}

/deep/ .el-tooltip {
  padding-left: 16px !important;
}

/* 当前选中点亮的框需要左右4px的margin，但是把icon和文字往右边挤了4px，所以需要把padding-left减少4px */
.el-menu-item, .el-submenu__title {
  height: 40px !important;
  line-height: 40px !important;
  padding-left: 16px !important;
  margin: 0 4px;
}

.el-submenu__icon-arrow {
  margin-top: -3px !important;
}

.el-submenu .el-menu-item {
  min-width: 0 !important;
}

.el-aside {
  transition: width .3s;
  box-shadow: 2px 0 6px rgba(0, 21, 41, .35);
}

.logo-title {
  margin-left: 5px;
  font-size: 20px;
  transition: all 0.3s;
}

.el-header {
  box-shadow: 2px 0 6px rgba(0, 21, 41, .35);
  display: flex;
  align-items: center;
}
</style>
